package zhoufu.sz.sanxiao_check.presents;

import javax.inject.Inject;
import zhoufu.sz.sanxiao_check.models.CheckItemModel;
import zhoufu.sz.sanxiao_check.net.BasicRequestRepository;
import zhoufu.sz.sanxiao_check.net.RequestHelper;
import zhoufu.sz.sanxiao_check.ui.contract.BasicMsgItem2Contract;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/8/5
 */
public class PrintPresenter implements BasePresent
{

    private BasicRequestRepository mRepository;

    private BasicMsgItem2Contract.View mView;

    private CheckItemModel _model;

    @Inject
    public PrintPresenter(BasicRequestRepository mRepository)
    {
        this.mRepository = mRepository;
    }

    public void bindView(BasicMsgItem2Contract.View mView)
    {
        this.mView = mView;
    }

    @Override public void onStart()
    {
        mRepository.GetLastExamineForPrint(mView.SID(),
                new RequestHelper.RequestCallBack<CheckItemModel>()
                {
                    @Override public void onPullStart()
                    {
                        mView.pullStart();
                    }

                    @Override public void onPullFailud(Throwable throwable)
                    {
                        mView.pullFaild();
                    }

                    @Override public void onPullEnd()
                    {
                        mView.pullEnd();
                    }

                    @Override public void onPullSuccessed(CheckItemModel s)
                    {
                        if ( s!=null&&s.isSuccess() )
                        {
                            if ( s.getData().size() > 0 )
                            {
                                _model = s.getData().get(0);
                                mView.setModel(s.getData().get(0));
                            }
                        } else
                        {
                            if(s==null) {
                                mView.showToast("网络异常");
                                return;
                            }
                            mView.showToast(s.getErrMsg());
                        }
                    }
                });
    }

    @Override public void onPause()
    {

    }

    @Override public void onDestroy()
    {
        mRepository.onDestory();
    }

    public CheckItemModel get_model()
    {
        if ( _model == null )
        {
            return new CheckItemModel();
        }
        return _model;
    }
}
